#!/usr/bin/python
# Author: Jimmy Saw
# Date: 10-16-2011
# This program parses MUMMER coordinate file for reads that fall within a given gap segment.
# 1. Run: nucmer ref.fasta illuminareads.fasta -p prefix
# 2. Run: show-coords -r -c -l -T prefix.delta > prefix.coords
# Usage: python gapspanningReads.py prefix.coords

import sys
import re
import itertools

mummerfile = open(sys.argv[1], "rU")
mfl = mummerfile.readlines()

gapstart = int(sys.argv[2])
gapstop = int(sys.argv[3])

for line in mfl[4:]:
    i = line.split('\t')
    readname = i[-1].rstrip()
    scafstart = int(i[0])
    scafstop = int(i[1])
    readstart = int(i[2])
    readstop = int(i[3])
    readorientation = ""
    if readstop > readstart:
        readorientation = "+"
    else:
        readorientation = "-"
    if scafstart < gapstart < scafstop or scafstart < gapstop < scafstop:
        #print readname + "\t" + readorientation
        print readname

mummerfile.close()
